import VueDatepickerLocal from 'vue-datepicker-local'
export default {
  name: 'TimeSlot',
  props: {
  	value:''
  },
  components:{
  	VueDatepickerLocal
  },
  data () {
  	 return {
  	 	showTime:false,
  	 	startText:new Date(),
  	 	start:new Date(),
  	 	end:'',
  	 	endText:'',
  	 	active:0
  	 }
  },
  mounted(){
	console.log('this.value',this.value);
	let now=new Date();
	this.endText=this.end=new Date(now.setDate(now.getDate()+1));
  
	let value=this.startText.getFullYear()+'-'+((this.startText.getMonth()+1)<10?('0'+(this.startText.getMonth()+1)):(this.startText.getMonth()+1))+'-'+(this.startText.getDate()<10?('0'+this.startText.getDate()):(this.startText.getDate()))+'&'+(this.endText?(this.endText.getFullYear()+'-'+((this.endText.getMonth()+1)<10?('0'+(this.endText.getMonth()+1)):(this.endText.getMonth()+1))+'-'+(this.endText.getDate()<10?('0'+this.endText.getDate()):(this.endText.getDate()))):'');
				this.$emit('input',value);
  },
  watch:{
	value(val){
		if(val){
			this.startText=new Date(this.value.split('&')[0]);
			this.start=new Date(this.value.split('&')[0]);
			this.endText=new Date(this.value.split('&')[1]);
			this.end=new Date(this.value.split('&')[1]);
		}
	},
  	active(val){
  		var odate=new Date(this.start);
  		switch(val){
  			case 1:
  			  this.end=new Date(odate.setDate(odate.getDate()+15));
  			break;
  			case 2:
  				this.end=new Date(odate.setDate(odate.getDate()+30));	
  			break;
  			case 3:
  				this.end=new Date(odate.setDate(odate.getDate()+60));	
  			break;
  			case 4:
  				this.end=new Date(odate.setDate(odate.getDate()+90));	
  			break;
  			case 5:
  			  odate.setMonth(odate.getMonth()+1);
  				this.end=new Date(odate.setDate(0));	
  			break;
  			case 6:
  			  odate.setMonth(odate.getMonth()+2);
  				this.end=new Date(odate.setDate(0));	
  			break;
  			case 7:
  				this.end=null;
  			break;
  		}
  		this.startText=this.start; 
  		this.endText=this.end 
  		this.showTime=false;
  	let value=this.startText.getFullYear()+'-'+((this.startText.getMonth()+1)<10?('0'+(this.startText.getMonth()+1)):(this.startText.getMonth()+1))+'-'+(this.startText.getDate()<10?('0'+this.startText.getDate()):(this.startText.getDate()))+'&'+(this.endText?(this.endText.getFullYear()+'-'+((this.endText.getMonth()+1)<10?('0'+(this.endText.getMonth()+1)):(this.endText.getMonth()+1))+'-'+(this.endText.getDate()<10?('0'+this.endText.getDate()):(this.endText.getDate()))):'');
			this.$emit('input',value);
  	}
  },
  methods:{
  	timeclick(){
  		this.showTime=true;
  	},
  	cancel(){
  		this.showTime=false;
  	},
  	sure(){
  		this.startText=this.start; 
  		this.endText=this.end;
		let value=this.startText.getFullYear()+'-'+((this.startText.getMonth()+1)<10?('0'+(this.startText.getMonth()+1)):(this.startText.getMonth()+1))+'-'+(this.startText.getDate()<10?('0'+this.startText.getDate()):(this.startText.getDate()))+'&'+(this.endText?(this.endText.getFullYear()+'-'+((this.endText.getMonth()+1)<10?('0'+(this.endText.getMonth()+1)):(this.endText.getMonth()+1))+'-'+(this.endText.getDate()<10?('0'+this.endText.getDate()):(this.endText.getDate()))):'');
			this.$emit('input',value);
  		this.showTime=false;
  	}
  }
}